from concurrent.futures import ThreadPoolExecutor
import requests
import uuid
import json
import sys
import os

sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

from model.car_number import CarNumber

from proxy.tunnel_proxy_service_qg import TunnelProxyService_QG
from common.logger import logger
from spider.jie_park_backup import JieParkSpider as JieParkSpiderWeb
from spider.jie_park import JieParkSpider as JieParkSpiderApp
from account.jie_account_service import JieAccountService

import spider_config

# 生成guid

proxy = TunnelProxyService_QG().take(spider_config.jie_park_id).build()

import threading

write_lock = threading.RLock()

def test():
    service = JieAccountService()
    service.active()
    while True:
        try:
            spider = JieParkSpiderApp()
            spider.setAccount(service.take())
            spider.setProxy(None)
            logger.success(spider.query(CarNumber("渝B3Q389")))
        except Exception as e:
            logger.exception(e)


if __name__ == "__main__":
    thread_count = 1

    thread_pool = ThreadPoolExecutor(max_workers=thread_count)

    futures = []
    for i in range(thread_count):
        futures.append(thread_pool.submit(test))

    thread_pool.shutdown(wait=True)
